using System.Web.Security;
using Castle.MonoRail.Framework;

namespace WineCellar.Web.Components
{
    public class LoginViewComponent:ViewComponent
    {
        private class Fields
        {
			public const string Username= "Username";

        }
        public override void Render()
        {
            RolePrincipal rolePrincipal=SecurityHelper.GetCurrentUser(this.EngineContext);

            if (rolePrincipal== null)
                Context.RenderSection("anonymous");
            else
            {
                PropertyBag[Fields.Username] = rolePrincipal.Identity.Name;
                Context.RenderSection("loggedIn");
            }
        }
        public override bool SupportsSection(string name)
        {
            return name == "loggedIn" || name == "anonymous";
        }

    }
}
